/**
 * Copyright (C) 2010 Cloudfarming <info@cloudfarming.nl>
 *
 * Licensed under the Eclipse Public License - v 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.cloudfarming.client.util;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.swing.filechooser.FileFilter;
import junit.framework.Assert;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 *
 * @author gerben
 */
public class FilePickerUtilIT {
    
    private File testfileDBF;
    private File testfileCSV;
    private File testfileTXT;
    private File testfileDOC;
    ArrayList supportedExtensions = new ArrayList();
            
    public FilePickerUtilIT() {
    }
    
    @Before
    public void setUp() throws IOException {
         testfileDBF = new File("test.dbf");
         testfileCSV = new File("test.csv");
         testfileTXT = new File("test.txt");
         testfileDOC = new File("test.doc");
      
         testfileDBF.createNewFile();
         testfileCSV.createNewFile();
         testfileTXT.createNewFile();
         testfileDOC.createNewFile();
                  
         supportedExtensions.add(".dbf");
         supportedExtensions.add(".csv");
    }
    
    @After
    public void tearDown() {
         testfileDBF.delete();
         testfileCSV.delete();
         testfileTXT.delete();
         testfileDOC.delete();
    }

    
    /**
     * Test creation of Swing filefilter (javax.swing.filechooser.FileFilter)
     */
     @Test
     public void createSwingFileFilterTest() {


         FileFilter ff = FilePickerUtil.createSwingFileFilter(supportedExtensions, "Description");
         
         Assert.assertTrue(ff.accept(testfileDBF));
         Assert.assertTrue(ff.accept(testfileCSV));
         Assert.assertFalse(ff.accept(testfileTXT));
         Assert.assertFalse(ff.accept(testfileDOC));
     }
     
     /**
      * Expected "All sensor files (*.dbf, *.csv)"
      */
     @Test
     public void getFileFilterDescriptionTest(){
         String preceedingText = "All sensor files";
         String description = FilePickerUtil.getFileFilterDescription(preceedingText, supportedExtensions);
         Assert.assertEquals("All sensor files (*.dbf, *.csv)", description);
         
     }
  
     /**
      * Expected "(*.dbf, *.csv)"
      */
     @Test
     public void getFileFilterTypeStringTest(){
        String description = FilePickerUtil.getFileFilterTypeString(supportedExtensions);
        Assert.assertEquals("(*.dbf, *.csv)", description);
     }    
}
